package com.cycrix.tcp;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class TcpAccelerometer extends TcpObject {
	
	private final int PACKET_SIZE = 24;
	
	public float _x, _y, _z;
	
	public TcpAccelerometer(float x, float y, float z)
	{
		_x = x;
		_y = y;
		_z = z;
	}

	@Override
	public int GetSize() {
		return PACKET_SIZE;
	}

	@Override
	public int GetStream(byte[] buffer, int size) {
		ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
		
		// Write size
		byteBuffer.putInt(0, PACKET_SIZE);
		
		// Write Code
		byteBuffer.putInt(4, TcpConnection.ENUM_ACCELEROMETER);
		
		// Write Checksum
		byteBuffer.putInt(8, TcpConnection.ENUM_ACCELEROMETER ^ PACKET_SIZE);
		
		// Data x
		byteBuffer.putFloat(12, _x);
		
		// Data y
		byteBuffer.putFloat(16, _y);
		
		// Data z
		byteBuffer.putFloat(20, _z);
		
		return PACKET_SIZE;
	}

	@Override
	public TcpObject FromStream(byte[] buffer) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int GetType() {
		// TODO Auto-generated method stub
		return TcpConnection.ENUM_ACCELEROMETER;
	}

}
